<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>Title</title>
    <link rel="stylesheet" href="../static/plugins/layui/css/layui.css">
</head>
<style>
    .ok-body {
        padding: 10px
    }
    .layui-form-item .layui-inline {
        margin-bottom: 5px;
        margin-right: 0px;
    }
    .layui-form-pane .layui-form-label {
        width: 90px;
    }
    .layui-form-item .layui-input-inline {
        width: 170px;
    }
</style>

<body>
<div class="ok-body">

    <div class="layui-row" style="margin-top: 15px">
        <form class="layui-form layui-form-pane" >

            <div class="layui-form-item">

                <div class="layui-inline">
                    <label class="layui-form-label">名称规格</label>
                    <div class="layui-input-inline" style="margin-right: 0px;">
                        <input class="layui-input" name="name"  autocomplete="off">
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">设备编号</label>
                    <div class="layui-input-inline" style="margin-right: 0px;">
                        <input class="layui-input" name="deviceNumber"  autocomplete="off">
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">更换人员</label>
                    <div class="layui-input-inline" style="margin-right: 0px;">
                        <select name="createId" lay-search>
                            <option value=""></option>
                        </select>
                    </div>
                </div>

                <div class="layui-inline">
                    <button class="layui-btn  layui-btn-normal" style="margin-left: 10px" lay-submit lay-filter="search">搜索</button>
                </div>
            </div>

        </form>

    </div>

    <hr class="layui-bg-orange">

    <table class="layui-hide" id="damageComponent" lay-filter="damageComponent"></table>
    <!--分页Div-->
    <div id="pageDiv"></div>

</div>

<script src="../static/plugins/layui/layui.js"></script>
<script src="../static/js/jquery-3.2.1.min.js"></script>
<script src="../static/js/jquery.base64.js"></script>
<script src="../static/js/device.js"></script>

<script th:inline="none">
    layui.use(['table','laypage','form'], function(){

        var table = layui.table;
        var form = layui.form;

        JJZ.initSelectShowField(JJZ.named('createId'), '/user/dataGrid', 'username', function (noError) {
            form.render();
        });
        var tableName = 'damageComponent';

        var tableRenderObject = {
            elem: '#'+tableName
            ,title: '更换零件'
            ,tableName:tableName
            ,searchCol:''
            ,searchValue:''
            ,defaultToolbar: ['filter', 'print']
            ,toolbar: true
            ,cols: [[
                {field:'deviceNumber', title:'所属设备编号',align:'center'}
                ,{field:'deviceName', title:'设备名称',align:'center'}
                ,{field:'name', title:'配件名称规格',align:'center'}
                ,{field:'unit', title:'单位',align:'center'}
                ,{field:'changeCount', title:'数量',align:'center'}
                ,{field:'startTime', title:'启用日期',align:'center',templet:function (d) {
                        return JJZ.FormatDate(d.startTime,'yyyy-MM-dd');
                    }}
                ,{field:'endTime', title:'损坏时间',align:'center',templet:function (d) {
                        return JJZ.FormatDate(d.endTime,'yyyy-MM-dd');
                    }}
                ,{field:'life', title:'使用寿命/天',align:'center'}
                ,{field:'creatorName', title:'更换者',align:'center'}
            ]]
        };

        var myTable = new JJZ.MyTable(tableRenderObject);

        form.on('submit(search)', function(data){
            var encodeStr = $.base64.encode(JSON.stringify(data.field), 'utf-8');
            var param = 'json=' + encodeURIComponent(encodeStr);
            tableRenderObject.initParam = param;
            myTable.render();
            return false;
        });


        //新增，跳转至页面
        $('#add').click(function(){
           myTable.add();
        });

        //批量删除数据
        $('#delete').click(function(){
            var checkStatus = table.checkStatus('damageComponent') //idTest 即为基础参数 id 对应的值
            ,data = checkStatus.data; //获取选中的数据
            layer.confirm('确认删除？', function(index){
                myTable.delete(data);
                myTable.render();
                layer.close(index);
            });
        });


    });

</script>
</body>
</html>